
import 'package:flutter/material.dart';

class PPInterestOptionsPostItem extends StatefulWidget {

    PPInterestOptionsPostItem({ Key key, this.type, this.data, @required this.itemWidth, this.action }): super(key: key);

    final String type;
    final Map data;
    final  double itemWidth;
    final Function action;
   
    _PPInterestOptionsPostItemState createState() => _PPInterestOptionsPostItemState();

}

class _PPInterestOptionsPostItemState extends State<PPInterestOptionsPostItem> {

    String type;
    Map data;
    double itemWidth;

    @override
    void initState() {
        type = widget.type;
        data = widget.data;
        itemWidth = widget.itemWidth;
        super.initState();
    }

    @override
    void didUpdateWidget(PPInterestOptionsPostItem oldWidget) {
        type = widget.type;
        data = widget.data;
        itemWidth = widget.itemWidth;
        super.didUpdateWidget(oldWidget);
    }

    @override
    Widget build(BuildContext context) {
        return (Container(
            margin: EdgeInsets.fromLTRB(15, 0, 0, 0),
            child: FlatButton(
                padding: EdgeInsets.all(0),
                child: Container( 
                    width: itemWidth,
                    margin: EdgeInsets.fromLTRB(0,6,0,6),
                    padding: EdgeInsets.fromLTRB(0, 5, 0, 5),
                    alignment: Alignment.center,
                    decoration: BoxDecoration(border: Border.all(width: 1, color: _getBorderColor(), style: BorderStyle.solid)),
                    child: Text(data["title"], style: TextStyle( fontSize: 14, fontWeight: FontWeight.w400, color: Color.fromRGBO(0, 0, 0, 1)), maxLines: 1),
                ),
                onPressed: _onClick,
            ),
        ));                           
    }

    _getBorderColor() {
        if(data["isSelect"]) {
            return Color.fromRGBO(63,227,206,1);
        } else {
            return Color.fromRGBO(24,25,25,0.33);
        }
    }

    _onClick() {
        if(widget.action != null) {
            widget.action(data, type);
        }
    }

}